﻿package sudoku {
	
	import flash.display.MovieClip;
	
	import flash.text.TextField;
	import flash.text.TextFieldType;
	
	public class SudokuRepresentation extends MovieClip {
		
		public function SudokuRepresentation() {
		}
		
		public function displayRawData():void {
			
			for(var i:uint=0; i<9; i++) {
				
				for(var j:uint=0; j<9; j++) {
					this["sudoku" + i + "" + j].text = j + "";
				}
				
			}
			
		}
		
		public function set editable(val:Boolean):void {
			
			for(var i:uint=0; i<9; i++) {
				
				for(var j:uint=0; j<9; j++) {
					if(val == true) {
						var t:TextField = new TextField();
						this["sudoku" + i + "" + j].type = TextFieldType.INPUT;
						this["sudoku" + i + "" + j].selectable = true;
					} else {
						this["sudoku" + i + "" + j].type = TextFieldType.DYNAMIC;
						this["sudoku" + i + "" + j].selectable = false;
					}
				}
				
			}
			
		}
		
		public function display(val:String):void {
			var aLines:Array = val.split("\r\n", 9);
			for(var i:uint=0; i<aLines.length; i++) {
				var aColumns:Array = aLines[i].split(" ", 9);
				for(var j:uint=0; j<aColumns.length; j++) {
					this["sudoku" + i + "" + j].text = aColumns[j];
				}
			}
		}
		
		
		public function clear(val:String):void {
			for(var i:uint=0; i<9; i++) {
				for(var j:uint=0; j<9; j++) {
					this["sudoku" + i + "" + j].text = "";
				}
			}
		}
		
	}
	
}